Skip to content

Harden loose-resource RNC decompression checks#125

Merged
segrax merged 1 commit into
masterfrom
codex/fix-unsafe-rnc-decompression-vulnerability
May 24, 2026
Merged

Harden loose-resource RNC decompression checks#125
segrax merged 1 commit into
masterfrom
codex/fix-unsafe-rnc-decompression-vulnerability

Conversation

@segrax
Copy link
Copy Markdown
Member

@segrax segrax commented May 24, 2026

Motivation

  • Close an unsafe decompression path introduced in the base resource loader where any non-empty loose resource could be treated as RNC and fed to the unpacker without size or result validation.
  • Prevent out-of-bounds reads, uncontrolled allocations, crashes, or potential memory corruption when parsing malformed or attacker-controlled loose assets (including DOS Amiga-audio replacements).

Description

  • In Source/Resources.cpp added a minimum-header length guard (RNCHeaderSize = 18) to avoid reading header fields from short buffers.
  • Read and validate the packed-size field and ensure PackedSize <= (buffer_size - RNCHeaderSize), and reject zero or excessively large unpacked sizes with a 64 MiB cap (MaxUnpackedSize).
  • Allocate the unpack buffer only after validation and call rnc_unpack, then verify the unpacker return value matches the expected unpacked size and fall back to returning the original buffer on any failure.
  • The changes are localized to cResources::fileDeRNC to provide a minimal defense-in-depth fix while preserving existing resource-loading behavior for valid data.

Testing

  • No automated tests were executed for this patch.

Codex Task

@segrax segrax merged commit d6f623b into master May 24, 2026
2 of 6 checks passed
@segrax segrax deleted the codex/fix-unsafe-rnc-decompression-vulnerability branch May 24, 2026 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant